<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <title>个人中心</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/bootstrap-fileupload.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <style>
        .list-group a {
            background-color: #393d49;
            border: 0px;
            color: white;

        }

        .list-group a:hover {
            background-color: #12967c;
            border: 0px;
            color: white;

        }

    </style>
</head>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <a href="">
            <div class="layui-logo">家政预约系统</div>
        </a>
        <!-- 头部区域（可配合layui已有的水平导航） -->

        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;"><span id="usernameheader">xs-shuai </span></a>
                <dl class="layui-nav-child">
                    <dd>
                        <a href="userInfo.html">个人中心</a>
                    </dd>
                    <dd>
                        <a href="/login/logout">注销登录</a>
                    </dd>

                </dl>
            </li>

        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <div class="list-group">
                <a href="index.html" class="list-group-item  ">首页</a>
                <a href="adviceManger.html" class="list-group-item">预约咨询</a>
                <a href="adviceOrderManger.html" class="list-group-item">邀请用户</a>
                <a href="courseHistory.html" class="list-group-item">查看公告</a>
                <a href="noticeBoard.html" class="list-group-item ">留言板</a>
                <a href="userInfo.html" class="list-group-item active">个人中心</a>
            </div>
        </div>
    </div>
    <div class="layui-body" style="padding:20px;">
        <!-- 内容主体区域 -->
        <!--显示个人信息-->

        <div class="form-horizontal">
            <input type="hidden" class="form-control" id="teaId" value="">
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    姓名</label>
                <div class="col-sm-4" id="teaName">
                </div>
               <!-- <div class="col-sm-4">
                    <a type="button" class="btn btn-info" data-toggle="modal" data-target="#phoneModal">修改手机号</a>
                </div>-->
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    账号</label>
                <div class="col-sm-4" id="teaPhone">
                </div>
               <!-- <div class="col-sm-4">
                    <a type="button" class="btn btn-info" data-toggle="modal" data-target="#passwordModal">修改密码</a>
                </div>-->
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">
                    性别</label>
                <div class="col-sm-8">
                    <div id="teasex">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">
                </label>
                <div class="col-sm-1">
                    <a type="button" class="btn btn-info" data-toggle="modal" data-target="#addmodal">修改信息</a>
                </div>
                <!--                <div class="col-sm-1">-->
                <!--                    <a type="button" class="btn btn-info" data-toggle="modal" data-target="#passwordModal">修改密码</a>-->
                <!--                </div>-->
            </div>
        </div>
        <div class="modal" id="addmodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
             data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabel">
                            修改
                        </h4>
                    </div>
                    <div class="modal-body">
                        <!--添加框-->
                        <div class="form-horizontal">
                            <input type="hidden" class="form-control" id="teaId-e" value="">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">
                                    姓名</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="teaName-e" placeholder="姓名">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">
                                    账号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="teaPhone-e" placeholder="账号">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">
                                    性别</label>
                                <div class="col-sm-8">
                                    <div id="teasex-e">
                                        <input type="radio" name="sex" value="0" checked> 男
                                        <input type="radio" name="sex" value="1"> 女
                                    </div>
                                </div>
                            </div>




                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            关闭
                        </button>
                        <button id="submit" type="button" class="btn btn-primary">
                            提交更改
                        </button>
                    </div>
                </div>
            </div>
        </div>
    <div class="layui-footer">
        © 2024 <a href="#">家政预约系统</a>
    </div>
</div>
<script src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/bootstrap-fileupload.js"></script>
<script src="../layui/layui.all.js"></script>
<script src="../js/myjs.js"></script>
<script src="../js/md5.js"></script>
<script>
    $(function () {
        shouimg();
        getDetail();
        $("#submit").click(function (){
            update();
        });
        $("#submitPhone").click(updatePhone);

        getCode();

    })


    function update() {
        //必填项验证
        var teaid = $("#teaId-e").val();
        var teaname = $("#teaName-e").val().trim();
        var teaphone = $("#teaPhone-e").val().trim();
        var teasex = $("input[name='sex']:checked").val();


        if (teaname.length == 0 || teaphone.length == 0 ) {
            layer.msg('请填写完整信息', {
                time: 1000,
                btn: ['好的']
            })
            return;
        }
        var json =
            {
                teaid: teaid,
                teaname: teaname,
                teaphone: teaphone,
                teasex: teasex
            }

        $.ajax({
            url: "/teacher/updateTeacher",
            type: "post",
            cache: false,
            contentType: "application/json",
            datatype: "json",
            data: JSON.stringify(json),
            success: function (response) {
                if (response.code == 200) {
                    layer.msg("修改成功，重新登录生效", {
                        time: 1000,
                        btn: ['好的']
                    })
                } else {
                    layer.msg(response.msg, {
                        time: 1000,
                        btn: ['好的']
                    })
                }
                allpassword = "";
            }
            ,
            error: function (response) {
                console.log("出错返回: " + response);
                console.log("出错数据: " + JSON.stringify(response));
            }
        });


    }

    //获得验证码
    function getCode() {
        $("#getCheckCode").click(function () {

            var phone = $("#codePhone").val().trim();
            // if (checkPhone(phone)) {
            //     layer.msg('手机号格式不正确', {
            //         time: 2000,
            //         btn: ['返回']
            //     });
            //     return;
            // }
            settime($("#getCheckCode"));
            var json = {phone: phone}
            $.ajax({
                url: "/login/getPhoneCode",
                type: "post",
                cache: false,
                contentType: "application/json",
                datatype: "json",
                data: JSON.stringify(json),
                success: function (response) {
                    if (response.code = 200) {
                        layer.msg('验证码发送成功!', {
                            time: 2000,
                            btn: ['返回']
                        });
                    }
                }
                ,
                error: function (response) {
                    console.log("出错返回: " + response);
                    console.log("出错数据: " + JSON.stringify(response));
                }
            });
        })
    }

    //修改手机号
    function updatePhone() {
        var json = {phone: $("#codePhone").val().trim(), number: $("#getcode").val().trim()}
        $.ajax({
            url: "/login/updatePhone",
            type: "post",
            cache: false,
            contentType: "application/json",
            datatype: "json",
            data: JSON.stringify(json),
            success: function (response) {
                if (response.code = 200) {
                    layer.msg('修改成功!', {
                        time: 1000
                    });
                } else {
                    layer.msg('修改成功!', {
                        time: 1000
                    });
                }

            }
            ,
            error: function (response) {
                console.log("出错返回: " + response);
                console.log("出错数据: " + JSON.stringify(response));
            }
        });


    }


    function updatepassword() {
        var oldpassword = $("#oldpassword").val().trim();
        var newpassword = $("#newpassword").val().trim();
        var confirmpassword = $("#confirmpassword").val().trim();
        if (oldpassword.length == 0 || newpassword.length == 0 || confirmpassword.length == 0) {
            layer.msg('填入完整密码', {
                time: 1000
            })
            return;
        }
        if (newpassword != confirmpassword) {
            layer.msg('密码不一致', {
                time: 1000
            })
            return;
        }
        var json = {oldpassword: hex_md5(oldpassword), newpassword: hex_md5(newpassword)}

        $.ajax({
            url: "/login/updatePasswordTeacher",
            type: "post",
            cache: false,
            contentType: "application/json",
            datatype: "json",
            data: JSON.stringify(json),
            success: function (response) {
                if (response.code == 200) {
                    layer.msg('修改成功', {
                        time: 1000
                    })
                    $('#submitbutton').attr("data-dismiss", "modal");
                } else {
                    layer.msg(response.msg, {
                        time: 1000
                    })
                }

            }
            ,
            error: function (response) {
                console.log("出错返回: " + response);
                console.log("出错数据: " + JSON.stringify(response));
            }

        })
    }

    function getDetail() {
        $.ajax({
            url: "/login/teacherInfo",
            type: "post",
            cache: false,
            contentType: "application/json",
            datatype: "json",
            success: function (response) {
                if (response.code == 200) {
                    showDetail(response.data);
                }

            }
            ,
            error: function (response) {
                console.log("出错返回: " + response);
                console.log("出错数据: " + JSON.stringify(response));
            }

        })
    }

    function showDetail(data) {
        $("#showImg").show();
        $("#teaId").val(data.teaid);
        $("#teaName").text(data.teaname);
        $("#teasex").text(getSex(data.teasex));
        $("#teaPhone").text(data.teaphone);
        $("#inDate").val(dateString(data.teastartdate));
        $("#birthDate").val(dateString(data.teabirth));
        $("#teadesc").val(data.teadescript);
        $("#showImg").attr("src", "../img/" + data.teaimg);
        //驾驶类型

        //getDriverClass(data.teadriver)

        $("#teaId-e").val(data.teaid);
        $("#teaName-e").val(data.teaname);
        $("#teasex-e").val(getSex(data.teasex));
        $("#teaPhone-e").val(data.teaphone);


    }

    //获得驾照类型
    function getDriverClass(teadriver) {
        $.ajax({
            url: "/driver/getDriverList",
            type: "post",
            cache: false,
            contentType: "application/json",
            datatype: "json",
            success: function (response) {
                for (var i = 0; i < response.data.length; i++) {
                    if (response.data[i].driverid == teadriver) {
                        $("#driverClass").text(response.data[i].driverdescription);
                        break;
                    }
                }
            }
            ,
            error: function (response) {
                console.log("出错返回: " + response);
                console.log("出错数据: " + JSON.stringify(response));
            }
        });

    }

    //验证倒计时
    var countdown = 60;

    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            obj.attr('disabled', false);
            obj.text("免费获取验证码");
            countdown = 60;
            return;
        } else {
            obj.attr('disabled', true);
            obj.text("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function () {
                settime(obj)
            }
            , 1000)
    }

    function checkPhone(phone) {
        if (!(/^1[34578]\d{9}$/.test(phone))) {
            return false;
        }
    }

</script>
</body>

</html>
